#EAN-13条形码对应二维码生成

#三种数字编码方式
A_ENCODE = {0:"0001101", 1:"0011001", 2:"0010011",3:"0111101",4:"0100011",5:"0110001",6:"0101111",7:"0111011",8:"0110111",9:"0001011"}
B_ENCODE = {0:"0100111", 1:"0110011", 2:"0011011",3:"0100001",4:"0011101",5:"0111001",6:"0000101",7:"0010001",8:"0001001",9:"0010111"}
C_ENCODE = {0:"1110010", 1:"1100110", 2:"1101100",3:"1000010",4:"1011100",5:"1001110",6:"1010000",7:"1000100",8:"1001000",9:"1110100"}

#前置码编码
first_code = {0:"AAAAAA", 1:"AABABB", 2:"AABBAB",3:"AABBBA",4:"ABAABB",5:"ABBAAB",6:"ABBBAA",7:"ABABAB",8:"ABABBA",9:"ABBABA"}

print('请输入12位码')
code = input()
barcode = ''

#计算校验位
temp1 = 0
temp2 = 0
for i in range(6):
    temp1 += int(code[2 * i])
    temp2 += int(code[2 * i + 1])
temp = temp1 + 3 * temp2
temp = 10 - temp % 10
code += str(temp)

#起始符
barcode += '101'

#左侧数据符
for i in range(6):
    if first_code[int(code[0])][i] == 'A':
        barcode += A_ENCODE[int(code[i + 1])]
    if first_code[int(code[0])][i] == 'B':
        barcode += B_ENCODE[int(code[i + 1])]

#中间分隔符
barcode += '01010'

#右侧数据符
for i in range(6):
    barcode += C_ENCODE[int(code[i + 7])]

#结束符
barcode += '101'

print('二进制EAN-13码:',int(barcode))
